package com.gc.jbnfgen.demo;

import com.gc.jbnfgen.gen.*;
import java.io.File;

/**
 *
 * @author dmitry.mamonov
 */
public class SqlDemoGen {
    public static void main(String[] args) {
        final JBNF openBr = new Constant("OpenBr","(");
        final JBNF closeBr = new Constant("CloseBr",")");
        final JBNF newLine = new Constant("NewLine","\n");
        final JBNF comma = new Constant("Comma",",");
        final JBNF columnDef = new Sequence("columnDef")
                .add(new Value(String.class,"name"))
                .add(new Value(int.class,"type"))
                .add(new Alternative("NullCheck"){{
                    add(new Constant("NotNull","NOT NULL"));
                    add(new Constant("Nuallable","NULL"));
                }})
                .add(new Alternative("DefaultValue"){{
                    add(new Constant("NoDefault",""));
                    add(new Sequence("defaultValue").add(new Constant("Default","DEFAULT")).add(new Value(String.class,"value")));
                }});
                //.add(newLine);

        final JBNF columnsSubList = new Alternative("ColumnsSubList");
        columnsSubList
                .add(new Sequence("columnInSubList"){{
                    add(comma);
                    add("column",columnDef);
                    add("next",columnsSubList);
                }})
                .add(new Sequence("ListCompleted").add(newLine).add(closeBr));

        final JBNF columnsList = new Sequence("ColumnsList")
                .add("columns",columnDef)
                .add("next",columnsSubList);

        final JBNF createTable = new Sequence("createTable")
                .add(new Constant("create","CREATE TABLE"))
                .add(new Value(String.class,"name"))
                .add(openBr)
                .add(newLine)
                .add(columnsList);


        JBNF sql = new Alternative("sql"){{
            add(createTable);
        }};

        new JBNFRenderer().render(new File("src"), new String[]{"com","gc","sql","ddl"},sql);
    }
}
